package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.PubCodetable;
import com.ruoyi.project.system.service.IPubCodetableService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 码Controller
 * 
 * @author ruoyi
 * @date 2019-12-23
 */
@RestController
@RequestMapping("/system/codetable")
public class PubCodetableController extends BaseController
{
    @Autowired
    private IPubCodetableService pubCodetableService;

    /**
     * 查询码列表
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:list')")
    @GetMapping("/list")
    public TableDataInfo list(PubCodetable pubCodetable)
    {
        startPage();
        List<PubCodetable> list = pubCodetableService.selectPubCodetableList(pubCodetable);
        return getDataTable(list);
    }

    /**
     * 导出码列表
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:export')")
    @Log(title = "码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PubCodetable pubCodetable)
    {
        List<PubCodetable> list = pubCodetableService.selectPubCodetableList(pubCodetable);
        ExcelUtil<PubCodetable> util = new ExcelUtil<PubCodetable>(PubCodetable.class);
        return util.exportExcel(list, "codetable");
    }

    /**
     * 获取码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return AjaxResult.success(pubCodetableService.selectPubCodetableById(code));
    }

    /**
     * 新增码
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:add')")
    @Log(title = "码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PubCodetable pubCodetable)
    {
        return toAjax(pubCodetableService.insertPubCodetable(pubCodetable));
    }

    /**
     * 修改码
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:edit')")
    @Log(title = "码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PubCodetable pubCodetable)
    {
        return toAjax(pubCodetableService.updatePubCodetable(pubCodetable));
    }

    /**
     * 删除码
     */
    @PreAuthorize("@ss.hasPermi('system:codetable:remove')")
    @Log(title = "码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(pubCodetableService.deletePubCodetableByIds(codes));
    }
}
